const express = require('express');
const router = express.Router();
const mongo2 = require('mongodb')
const examination = require('../../bin/control/examinationControl');
const paperModel = require('../../bin/models/paperModels')
module.exports =
    router.post('/addExamination', function (req, res, next) { // 插入文章
       examination.addExamination(req.body)
       res.send('success')
    });

    router.get('/allExamination', function (req, res, next) { // 查询所有套题
      examination.findAllExamination((allData)=>{
         for(let i in allData){
            allData[i].number = parseInt(i)+1
         }
         res.send(allData)
      })
   });
   router.get('/OneExamination', function (req, res, next) { // 查询单个文章
      let _id = req.query._id
      examination.findOneExamination(_id,(allData)=>{
         res.send(allData)
      })
   //    console.log(req.body)
   });
   router.post('/deleteExamination', function (req, res, next) { // 删除文章
      let _id = req.body._id
      examination.deleteOneExamination(_id,(allData)=>{
         res.send('删除成功')
      })
   });
   router.post('/editorExamination', function (req, res, next) { // 更新文章
      console.log(req.body)
      let data = req.body
      examination.updateExamination(data, (allData) => {
         res.send(allData)
      })
   });
   router.post('/jiaojuan', function (req, res, next) { // 交卷
      console.log(req.body)
      let data = req.body
      examination.setPaperAndGrade(data, (allData) => {
         res.send(allData)
      })
   });
   router.post('/getGrade', function (req, res, next) { // 交卷
      console.log(req.body)
      let data = req.body
      paperModel.find(({}), (allData) => {
         res.send(allData)
      })
   });
      
